﻿Imports System.Data.SqlClient
Public Class frmKhachHang
    Private Sub frmKhachHang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CapNhatLuoi()
    End Sub

    Private Sub CapNhatLuoi()
        Dim strSql As String = "select ROW_NUMBER() OVER (ORDER BY maKH) as STT, maKH as [Mã khách hàng], tenkh as [Tên khách hàng], diachi as [Địa chỉ], sodt as [Số điện thoại], masothue as [Mã số thuế], tknganhang as [TK Ngân hàng] from KhachHang "
        Dim myConn As New SqlConnection(modKetNoi.strConnectionString)
        Dim myTable As New DataTable
        Try
            myConn.Open()
            If txtKey.Text <> "" Then
                If radMaKH.Checked = True Then
                    strSql &= " Where MaKH = '" & txtKey.Text & "'"
                ElseIf radTenKH.Checked = True Then
                    strSql &= " Where TenKH like N'%" & txtKey.Text & "%'"
                Else
                    strSql &= " Where DiaChi like N'%" & txtKey.Text & "%'"
                End If
            End If
            strSql &= " order by STT"
            Dim myAdapter As New SqlDataAdapter(strSql, myConn)
            myAdapter.Fill(myTable)
            dgvList.DataSource = myTable
            dgvList.Columns.Item(0).Width = 50
            dgvList.Columns.Item(1).Width = 120
            dgvList.Columns.Item(2).Width = 200
            dgvList.Columns.Item(3).Width = 300
            dgvList.Columns.Item(4).Width = 150
            dgvList.Columns.Item(5).Width = 150
            dgvList.Columns.Item(6).Width = 150

        Catch ex As Exception

        End Try
        myConn.Close()
        myConn.Dispose()
    End Sub

    Private Sub btnTim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim.Click
        CapNhatLuoi()
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDong.Click
        Close()
    End Sub
End Class